package wx.controls
{
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	
	import wx.core.SettingCache;
	import wx.core.ViewManager;
	import wx.display.BorderSprite;
	
	/**
	 * 
	 * @author 
	 * 应用程序主页面,顶层需继承
	 * 
	 */	
	public class ViewMain extends BorderSprite
	{
		
		private var _hasInit:Boolean = false;
		private var _isWindowMode:Boolean = SettingCache.isWindowMode;

		public function ViewMain()
		{
			super();
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;			
			stage.addEventListener(Event.RESIZE,updateSize);
			
			backgroundColor = 0xFFFFFF;
			ViewManager.top = this;
		}
				
		/**
		 * 定义手机项目模式(含Web模式), 桌面应用需为false
		 */			
		protected function set isNativeWindowMode(value:Boolean):void
		{
			SettingCache.isWindowMode = value;
			_isWindowMode = value;
		}
		
		/**
		 * 改变系统默认皮肤
		 */	
		protected function set theme160dpi(value:Class):void
		{
			SettingCache.theme160dpi = value;
		}
		protected function set theme240dpi(value:Class):void
		{
			SettingCache.theme160dpi = value;
		}
		protected function set theme320dpi(value:Class):void
		{
			SettingCache.theme160dpi = value;
		}

		/**
		 * 初始化,需重写
		 * 
		 */		
		protected function initialize():void {}
		
		/**
		 * 
		 * 获取界面尺寸，绘制组件
		 * 
		 */		
		private function updateSize(e:Event = null):void{
			if(_isWindowMode){
				SettingCache.mainWidth = stage.nativeWindow.width;
				SettingCache.mainHeight =  stage.nativeWindow.height;			
			}else{
				SettingCache.mainWidth = stage.stageWidth;
				SettingCache.mainHeight = stage.stageHeight;
			}
			
			if(this.width != SettingCache.mainWidth)
				this.width = SettingCache.mainWidth;
			
			if(this.height != SettingCache.mainHeight)
				this.height = SettingCache.mainHeight;
			
			if(!_hasInit){
				_hasInit = true;
				initialize();
			}
		}
		
		
		
	}
}